package com.dawnClass.controller;

import com.dawnClass.pojo.Consumer;
import com.dawnClass.service.OrderService;
import com.dawnClass.util.ServiceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
@ResponseBody
public class OrderController {
    @Autowired
    private OrderService orderService;
    /*通过consumer ID 求订单总数*/


    /*通过consumer ID 查询他的全部订单*/
    @GetMapping(value = {"myorder/{status}"})
    public ModelAndView orderSelect(@PathVariable(value="status",required=false) Integer status ,
                                    HttpSession session){
        ServiceResponse consumerResponse = (ServiceResponse)session.getAttribute("ServiceResponse");
        Consumer consumer = (Consumer) consumerResponse.getdata();
        ServiceResponse serviceResponse = orderService.getOrderByConsumerId(consumer.getConsumerId(),status);
        ModelAndView mav = new ModelAndView();
        mav.addObject("status",status);
        mav.addObject("serviceResponse",serviceResponse);
        mav.setViewName("pay/myorder");
       return mav;
    }


    /*删除订单*/
    @PostMapping("myorder")
    public ModelAndView delete( Integer orderId , Integer status , HttpSession session){
         ServiceResponse ord_del =  orderService.deletebyId(orderId);
        ModelAndView modelAndView = this.orderSelect(status, session);
        return modelAndView;
    }
}
